﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BusinessEntities.Model;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Reflection;
using System.IO;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Data.Entity.Infrastructure;
using System.Diagnostics;

namespace DAL
{
    public class EventsDB : DbContext
    {
        public DbSet<Guest> Guests { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Event> Events { get; set; }
        public DbSet<Hall> Halls { get; set; }
        public DbSet<Invite> Invites { get; set; }
        public DbSet<City> Cities { get; set; }
        public DbSet<Gift> Gifts { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //TODO: Maybe look into not needing these things.
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
        }

        public EventsDB() : base()
        {
           // Debug.WriteLine((this as IObjectContextAdapter).ObjectContext.CreateDatabaseScript());
            if (Cities.Count() == 0)
            {
                EventsInitializer.PubSeed(this);
            }
            //Configuration.LazyLoadingEnabled = false;
            //Configuration.ProxyCreationEnabled = false;
        }

        

    }

}
